﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using DataForest.DataModel;

namespace DataForest.View.Converter
{
    class IsHighlightedConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            DataRowView selectedRowView = null;
            DataRow selectedRow = null;
            Node node = null;
            bool showRules = false;

            foreach (object item in values)
            {
                if (item is DataRowView)
                {
                    selectedRowView = item as DataRowView;
                }

                if (item is DataRow)
                {
                    selectedRow = item as DataRow;
                }
                
                if (item is Node)
                {
                    node = item as Node;
                }

                if (item is bool)
                {
                    showRules = (bool) item;
                }
            }

            if (showRules)
            {
                if (selectedRowView != null && node != null)
                {
                    return node.Objects.Any(row => selectedRowView.Row == row);
                }
                if (selectedRow != null && node != null)
                {
                    return node.Objects.Any(row => selectedRow == row);
                }
            }
            return false;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
